//
//  ViewController.swift
//  GGTableViewController
//
//  Created by lisheng on 16/3/15.
//  Copyright © 2016年 鬼谷传人. All rights reserved.
//

import UIKit

class ViewController: UIViewController,GGTableViewControllerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        // Do any additional setup after loading the view.
        
        view.backgroundColor = UIColor.magentaColor()
        
        
        let btn = UIButton(type: .Custom)
        btn.frame = CGRect(x: 50, y: 50, width: 80, height: 30)
        btn.setTitle("弹出", forState: .Normal)
        btn.backgroundColor = UIColor.greenColor()
        btn.addTarget(self, action: "btnClicked", forControlEvents: .TouchUpInside)
        view.addSubview(btn)
        
    }
    
    func btnClicked() {
        print("btn clicked")
        
        //将GGTableViewController的view 添加到self.view上,并且建立self与GGTableViewController的父子关系
        /*
        This relationship is necessary when embedding the child view controller’s view into the current view controller’s content.
        */
        let vc = GGTableViewController()
        
        vc.delegate = self
        
        view.addSubview(vc.view)
        
        self.addChildViewController(vc)
        
        vc.didMoveToParentViewController(self)
        
    }
    //MARK: GGTableViewControllerDelegate
    func closeButtonDidClicked() {
        print("will close")
        
        let ggView = view.subviews.last
        
        ggView?.removeFromSuperview()
        
    }
    
    func tableViewDidSelectedAtIndexPath(indexPath: NSIndexPath) {
        print(indexPath)
    }


}

